<template>
	<view class="content poRel" :style="'background: linear-gradient('+theme.ba_color+' 2%, #F3F1F1 15%);'">
		<view class="wid100">
			<view style="height: 30rpx;"></view>
			<view class="wid90 mar dis disAl disJuC borRad40 bacFFF" style="height: 72rpx;">
				<view class="dis disJuC" style="width: 13%;">
					<uni-icons type="search" size="30rpx" color="#AFB6B1"></uni-icons>
				</view>
				<input class="wid85 foSi25" v-model="sousuo" @input="sousuoInput" 
					placeholder="请输入技师姓名" placeholder-style="color: #AFB6B1;"/>
			</view>
			<view class="wid90 mar dis disAl hei86 mar-top10 fowe600" style="justify-content: space-around;">
				<view :style="xuanze == 0?'border-bottom: 6rpx solid '+theme.main_color+';color: '+theme.main_color+';':'border-bottom: 6rpx solid #F3F1F1;'"
				 class="dis disAl hei80" @click="xuan(0)">推荐</view>
				<view :style="xuanze == 1?'border-bottom: 6rpx solid '+theme.main_color+';color: '+theme.main_color+';':'border-bottom: 6rpx solid #F3F1F1;'"
				 class="dis disAl hei80" @click="xuan(1)">关注</view>
			</view>
		</view>
		<scroll-view style="height: calc(100vh - 200rpx);" class="wid100" scroll-y="true" @scrolltolower="lower">
			<wsj v-if="list.length == 0" zs='0'></wsj>
			<view style="height: 1rpx;"></view>
			<view class="wid90 mar dis disAl disJuB flwa">
				<block v-for="(item,index) in list" :key="index">
					<view class="borRad10 bacFFF mar-top30 poRel" @click="xiangqing(item)"
						style="width: 48%;overflow: hidden;">
						<image :src="item.trends_coverimg" class="wid100" style="height: 320rpx;"></image>
						<image v-if="item.type == '视频'" :lazy-load="true" src="../../static/bofang.png" class="poAbs"
							style="z-index: 1;width: 62rpx;height: 62rpx;top: 109rpx;left: 124rpx;"></image>
						<view class="wid90 mar mar-top10">
							<view class="foSi25 fowe600" style="line-height: 40rpx;">{{item.title}}</view>
							<view class="dis disAl disJuB mar-top10">
								<view class="dis disAl">
									<image :lazy-load="true" :src="item.coverimg" style="width: 34rpx;height: 34rpx;" class="borRad50 mar-right10"></image>
									<view class="foSi18 fowe600">{{item.name}}</view>
								</view>
								<view class="dis disAl">
									<uni-icons type="location-filled" size="25rpx" :color="theme.main_color"></uni-icons>
									<view class="foSi15 mar-left10">{{item.km}}</view>
								</view>
							</view>
						</view>
						<view style="height: 20rpx;"></view>
					</view>
				</block>
			</view>
			<view style="height: 100rpx;" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}"></view>
		</scroll-view>
		<tablist :back="theme.main_color" :datalist="datalist" :index="3"></tablist>
		<view class="poFix dis disAl disJuC borRad50" @click="tiaozhuan('/pages/dynamically/video')" v-if="duan == 1"
			:style="'background-color: '+theme.main_color+';'" style="height: 100rpx;width: 100rpx;bottom: 20%;right: 20rpx;z-index: 10;">
			<view>
				<view class="mar" style="width: 30rpx;height: 30rpx;">
					<image src="../../static/pinglun1.png" class="wh100"></image>
				</view>
				<view class="textCen coFFF foSi20 mar-top10">发布</view>
			</view>
		</view>
	</view>
</template>

<script>
	import tablist from "../common/tablist/tablist.vue"
	import wsj from '../common/w_sj.vue'
	export default {
		components: {
			wsj,tablist
		},
		data() {
			return {
				url: this.global.url,
				xuanze: 0,
				timer: null,
				sousuo: '',
				last_page: 0,
				page: 1,
				list: [],
				duan: 0,
				theme: null,
				datalist: [],
				paddingBottomHeight: 0
			}
		},
		created() {
			let that = this;
			uni.hideTabBar()
			uni.getSystemInfo({
				success: function (res) {
					let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
					model.forEach(item => {
						//适配iphoneX以上的底部，给tabbar一定高度的padding-bottom
						if(res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
							that.paddingBottomHeight = 40;
						}
					})
				}
			});
		},
		onLoad() {
			this.datalist = uni.getStorageSync('bom')
			this.theme = uni.getStorageSync('theme')
			uni.setNavigationBarColor({
				frontColor: '#000000',
				backgroundColor: this.theme.ba_color,//底部背景色
			})
		},
		onShow(){
			this.duan = uni.getStorageSync('duan');
			this.page = 1
			this.getList()
		},
		methods: {
			getList(){
				var that = this;
				uni.request({
					url: that.global.url + 'api/qianyu_smfw/trends/lists',
					method: "POST",
					header: {
						'site-id': that.global.site_id ,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						keywords: that.sousuo,
						lon: uni.getStorageSync('lon')?uni.getStorageSync('lon'):125.35043,
						lat: uni.getStorageSync('lat')?uni.getStorageSync('lat'):43.86414,
						page: that.page,
						is_type :that.xuanze
					},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							that.last_page = result.data.last_page
							if(that.page == 1){
								that.list = result.data.data
							}else{
								that.list = that.list.concat(result.data.data)
							}
						}else{
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							}) 
						}
					}
				})
			},
			xiangqing(item){
				var that = this
				if(item.type == '图片'){
					that.tiaozhuan('/pages/dynamically/pictureParticulars?id='+item.id)
				}else{
					that.tiaozhuan('/pages/dynamically/videoParticulars?id='+item.id)
				}
			},
			xuan(index){
				if(this.xuanze != index){
					if(!uni.getStorageSync('token')){
						return uni.showToast({title: '请登录',icon: 'error',duration: 2000}) 
					}
					this.xuanze = index
					this.page = 1
					this.getList()
				}
			},
			sousuoInput: function(event) {
				var that = this
				if (that.timer !== null) clearTimeout(that.timer)
				that.timer = setTimeout(() => {
					that.sousuo = event.target.value
					console.log(that.sousuo)
					that.page = 1
					that.getList()
				}, 1000)
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					this.getList()
				}
			},
			tiaozhuan(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.content {
		min-height: 100vh;
	}
</style>